<!DOCTYPE html>
<html>
<head>
    <title>DeepSeek 本地调用</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
</head>
<body>
    <div class="container">
        <h1>DeepSeek 本地智能助手</h1>
        <form id="inputForm" enctype="multipart/form-data">
            <div class="form-group">
                <label for="text">输入文本：</label>
                <textarea id="text" name="text" rows="5"></textarea>
            </div>
            <div class="form-group">
                <label for="file">上传文件：</label>
                <input type="file" id="file" name="file">
                <small>支持格式：txt/pdf/docx（最大16MB）</small>
            </div>
            <button type="submit">提交</button>
        </form>
        <div id="result" class="result-box"></div>
    </div>

    <script>
        document.getElementById('inputForm').addEventListener('submit', async (e) => {
            e.preventDefault();
            const formData = new FormData();
            formData.append('text', document.getElementById('text').value);
            if (document.getElementById('file').files[0]) {
                formData.append('file', document.getElementById('file').files[0]);
            }

            try {
                const response = await fetch('/process', {
                    method: 'POST',
                    body: formData
                });
                const data = await response.json();

                if (data.error) {
                    document.getElementById('result').innerHTML =
                        `<div class="error">${data.error}</div>`;
                } else {
                    document.getElementById('result').innerHTML =
                        `<div class="success">${data.result.replace(/\n/g, '<br>')}</div>`;
                }
            } catch (error) {
                document.getElementById('result').innerHTML =
                    `<div class="error">请求失败：${error.message}</div>`;
            }
        });
    </script>
</body>
</html>